home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000109_icon-group-sender_Wed Oct 25 08:09:54 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9PF9kc09413
  4.     for icon-group-addresses; Wed, 25 Oct 2000 08:09:46 -0700 (MST)
  5. Message-Id: <200010251509.e9PF9kc09413@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 24 Oct 2000 21:23:19 -0400
  7. From: David Gamey <dgamey@sympatico.ca>
  8. X-Accept-Language: en
  9. To: icon-group@cs.arizona.edu
  10. CC: Chris.D.Tenaglia@jci.com
  11. Subject: Re: Icon beginner
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14. Content-Length: 1745
  15.  
  16. Chris.D.Tenaglia@jci.com wrote:
  17. > I like simple things like...
  18. > procedure despace(str)
  19. >   new := ""
  20. >   every byte := !string do if byte ~== " " then new ||:= byte
  21.  
  22. Ooops, this typo "!string" instead of "!str" won't work.  I'd expect to
  23. see a type error here since string is a builtin function.
  24.  
  25. >   return new
  26. >   end
  27.  
  28. There's always 'strip' in the Icon programming library, see
  29. http://www.cs.arizona.edu/icon/library/src/procs/strip.icn 
  30.  
  31. But if you insist on doing it yourself try a slightly terser version of
  32. Chris's code:
  33.  
  34.     procedure despace(str)
  35.     new := ""
  36.     every new ||:= ( " " ~== !str )
  37.     return new
  38.     end
  39.  
  40. In the above, every generates each character in str.  Then if the ~==
  41. succeeds, the ~== operator returns its' right argument for the
  42. concatenation.
  43.  
  44. Chris's example is probably easier for someone new to Icon to decipher. 
  45. After writing Icon for a while I find the second is clearer and more
  46. straightforward.
  47.  
  48. You could with minor changes make this work like strip.  However, it
  49. wouldn't likely be as elegant or as fast.  An interesting difference in
  50. the use of every .vs. while (and the integration of control structures
  51. with string scanning).
  52.  
  53.  
  54. > Chris Tenaglia, tech analyst, jci
  55. > kaurp@cs.ucdavis.edu on 10/23/2000 01:56:42 PM
  56. > To:   icon-group@CS.Arizona.EDU
  57. > cc:
  58. > bcc:
  59. > Subject:  Icon beginner
  60. > Hi,
  61. >   I'm just learning icon and I'm stumped with a particular problem.  I'm
  62. > suppose to delete all occurrences of a space from a sentence, i.e. "Hi
  63. > there" should become "Hithere".  Any ideas of how I should approach this
  64. > problem.  I tried using the built-in delete proc. but it wasn't working.
  65.  
  66. delete works with structures (e.g. sets)
  67.  
  68. > I'd appreciate any help, thanks!
  69. > -Cos
  70.  
  71.  
  72. David Gamey
  73.